<!DOCTYPE html>
<html lang="en">
  <head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <script src="./static/vconsole.min.js" defer rel="prefetch"></script>
  </head>
  <body>
    <script>
      window.onload = function() {
        var vConsole = new window.VConsole();
        console.log('navigator===>', navigator.geolocation.getCurrentPosition((position)=>{
          var vConsole = new window.VConsole();
          console.log('未知信息===》',position);

        },(code,msg)=>{
          var vConsole = new window.VConsole();
          console.log('error====>', code,msg);

        },{enableHighAccuracy:true , timeout:0 , maximumAge:0}))
        // console.log('navigator===>', navigator.geolocation.clearWatch())
        // console.log('navigator===>', navigator.geolocation.watchPosition())

      const memory = navigator.deviceMemory
      console.log(`此设备至少拥有 ${memory}GiB 的 RAM。`)

      var geoHandler = function(position)
    {
        var geoMsg = "用户的所在的地理位置信息是：<br/>";
        geoMsg += "timestamp属性为：" + position.timestamp + "<br/>";
        // 获取Coordinates对象，该对象里包含了详细的地理位置信息
        var coords = position.coords;
        // 遍历Coordinates对象的所有属性
        for(var prop in coords)
        {
            geoMsg += prop + "-->" + coords[prop] + "<br/>";
        }
        // 输出地理位置信息
        document.writeln(geoMsg);
    }
    var errorHandler = function(error)
    {
        // 为不同错误代码定义错误提示
        var errMsg = {
            1: '用户拒绝了位置服务',
            2: '无法获取地址位置信息',
            3: '获取地理位置信息超时'
        };
        // 弹出错误提示
        alert(errMsg[error.code]);
    }
    // 获取地理位置信息
    navigator.geolocation.getCurrentPosition(geoHandler
        , errorHandler
        , {
            enableHighAccuracy:true,
            maximumAge:1000
        }); 
      }
    </script>
  </body>
</html>
